﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.OracleClient;
using System.Data;
using NHibernate;
using dbPoll_Application.Helpers;
using NHibernate.Criterion;
using NHibernate.Linq;

namespace dbPoll_Application.Models
{
    public static class TemplateRepository
    {
        public static OptionsTemplate GetOptionsTemplateByName(String name)
        {
            ISession session = NHibernateHelper.GetCurrentSession();
            var template = (from item in session.Query<OptionsTemplate>()
                            where item.name == name
                            select item).FirstOrDefault<OptionsTemplate>();
            return template;
        }

        public static ICollection<OptionsTemplate> GetAllOptionsTemplates()
        {
            ISession session = NHibernateHelper.GetCurrentSession();
            var templates = from item in session.Query<OptionsTemplate>()
                           select item;
            return templates.ToList<OptionsTemplate>();
        }

        public static IList<String> GetAllOptionsTemplateNames()
        {
            ISession session = NHibernateHelper.GetCurrentSession();
            var templates = from item in session.Query<OptionsTemplate>()
                            select item.name;
            return templates.ToList<String>();
        }
    }
}
